package com.filldream.fastboot.core.manager;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.filldream.fastboot.base.entity.Area;
import com.filldream.fastboot.base.mapper.AreaMapper;
import com.filldream.fastboot.base.request.common.area.AreaListSTO;
import com.filldream.fastboot.base.response.common.AreaDTO;
import com.filldream.fastboot.common.util.ListUtil;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author RickSun && iFillDream
 * @version 1.0
 * @data 2020-05-07 18:21
 * @description AreaManager
 */
@Service
public class AreaManager {

    @Resource
    private AreaMapper areaMapper;

    //获取下级列表
    public List<Area> getByParentId(AreaListSTO areaListSTO){
        List<Long> idList = new ArrayList<>();
        Long id = areaListSTO.getPId();
        idList.add(id);
        if( id.equals(0L) && areaListSTO.getHasLocation().equals(0) ){
            List<Area> areas = areaMapper.selectList(
                    new QueryWrapper<Area>().eq("type", 0)
            );
            idList = ListUtil.getParamList(areas, "id", Long.class);
        }
        return areaMapper.selectList(
                new QueryWrapper<Area>().in("p_id",idList)
        );
    }



    //还原所有的列表
    public AreaDTO getByParentId(List<Long> ids){

        List<Area> areaList = areaMapper.selectList(new QueryWrapper<Area>().in("id", ids));


        return null;
    }


}
